package com.chinatsp.onlineapp.ui.violation;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.bean.CityList;

/**
 * 城市列表 适配器
 */

public class CityListAdapter extends BaseAdapter {
    private Context mContext;
    private List<CityList> cityLists;

    public CityListAdapter(Context context, List<CityList> cityLists) {
        mContext = context;
        this.cityLists = cityLists;
    }

    @Override
    public int getCount() {
        return cityLists == null ? 0 : cityLists.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_city_list_item, parent, false);
            holder = new ViewHolder();

            holder.cbxIsSelect = (CheckBox) convertView.findViewById(R.id.cbx_city);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.cbxIsSelect.setChecked(cityLists.get(position).isChecked());
        holder.cbxIsSelect.setText(cityLists.get(position).getName()+"("+cityLists.get(position).getId()+")");

        return convertView;
    }

    static class ViewHolder {

        CheckBox cbxIsSelect;
    }

}
